// app.js
const {login} = require('./utils/api');
App({
  onLaunch() {
    // 展示本地存储能力
    const logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)
    wx.setStorageSync('current-page', 0)
    // 登录
    wx.login({
      success: async res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
        const config = {
          data: {code: res.code},
        }
        const result = await login(config);
        const {token, name, avatar} = result.data;
        wx.setStorageSync('token', token);
        wx.setStorageSync('userInfo', {name, avatar});
      }
    })
  },
  globalData: {
    userInfo: null
  }
})
